/*
 * Parser.cpp
 *
 *  Created on: Jun 19, 2012
 *      Author: hugo
 */

#include "Parser.h"
#include <stdio.h>
#include <stdlib.h>

Parser::Parser(string _file_name) {
	file_name = _file_name;
	parse_file();
}

void Parser::parse_file(){
	ifstream inst_file;
	inst_file.open(Parser::file_name.c_str());
	if (inst_file.is_open()) {
		bool has_end=false;
		string label;
		while (!has_end && !inst_file.eof()) {
			inst_file >> label;
			if(label==LABEL_TIME){
				inst_file >> time;
				inst_file >> label;
			}else if(label==LABEL_OBJ){
				inst_file >> value;
				has_end=true;
			}
		}
		while(!inst_file.eof()){
			float tmp_p;
			inst_file >> label;
			inst_file >> tmp_p;
			string sub;
			if(label.at(label.size()-1)==':')
				sub = label.substr(1,label.size()-2);
			else
				sub = label.substr(1,label.size());
			int num = atoi(sub.c_str());
			if(var_p.size()==0 || var_p.at(var_p.size()-1)!=num)
				var_p.push_back(num);
		}
	}
}

float Parser::get_time(){
	return time;
}
float Parser::get_value(){
	return value;
}
float Parser::get_p(int i){
	return var_p[i];
}

long Parser::qnt_p(){
	return var_p.size();
}

Parser::~Parser() {
	// TODO Auto-generated destructor stub
}
